<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    input {
      width: 200px;
      transition: all .3s;
    }

    /* focus伪类选择器  获得焦点 */
    input:focus{
      width: 300px;
    }
  </style>
</head>

<body>
  <input type="text">
  <!-- 分别用CSS和JS的方式实现：输入框获得焦点，就将其宽度变为300px -->
  <script>
    document.querySelector('input').addEventListener('focus',function(){
      document.querySelector('input').style.width='300px '
    })
  </script>
</body>

</html>